
cc.Class({
    extends: cc.Component,

    properties: {
        handNode:{
            default:null,
            type:cc.Node
        },

        lightNode:{
            default:null,
            type:cc.Node
        },

        btnGroup:{
            default:null,
            type:cc.Node
        },

        labelContent:{
            default:null,
            type:cc.Label
        },

        labelClick:{
            default:null,
            type:cc.Label
        }

    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.handNode.active = false
    },

    start () {
        cc.gg.gameDataUtil.setFakeNodePosition(this.lightNode.children)
        this.startGuildHandAnim()

        // this.labelContent.string = cc.gg.i18n.getSentence(cc.gg.i18n.sentence.G_GROUP_SET)
        // this.labelClick.string = cc.gg.i18n.getSentence(cc.gg.i18n.sentence.G_CLICK_EACH)
    },

    // update (dt) {},

    startGuildHandAnim:function () {
        let interval = 1
        let maxDelay = 0
        for(let i=0;i<this.lightNode.children.length;i++){
            this.lightNode.children[i].stopAllActions()
            cc.find("border",this.lightNode.children[i]).active = false

            maxDelay = i * interval
            this.scheduleOnce(function () {
                this._startOneNodeAnim(this.lightNode.children[i])
            }.bind(this), maxDelay)
        }

        this.scheduleOnce(function () {
            this.startGuildHandAnim()
        }.bind(this), maxDelay + interval)
    },

    onGuild3PokerClicked:function (event) {
        if(event.target.uped) return

        event.target.y += 20
        event.target.uped = true
        for(let i=0;i<this.lightNode.children.length;i++){
            let node = this.lightNode.children[i]
            if(!node.uped){
                return
            }
        }

        for(let i=0;i<this.lightNode.children.length;i++) {
            this.lightNode.children[i].stopAllActions()
            cc.find("border", this.lightNode.children[i]).active = false
        }
        //todo show group button
        this.btnGroup.active = true
    },

    onGuild3GroupBtnClicked:function (event) {
        cc.find("Canvas").emit("guild_group_10q10")
    },

    _startOneNodeAnim:function (node) {
        let worldPos = node.parent.convertToWorldSpaceAR(node.position)
        let nodePos = this.handNode.parent.convertToNodeSpaceAR(worldPos)
        this.handNode.position = nodePos
        cc.log("小手现在的位置：",nodePos)

        let self = this
        let array = []
        array.push(cc.scaleTo(0.4,0.8))
        array.push(cc.callFunc(function () {
            self._startBorderBlink(cc.find("border",node))
        },this))
        array.push(cc.scaleTo(0.2,1))
        this.handNode.active = true
        this.handNode.runAction(cc.sequence(array))
    },

    _startBorderBlink:function (borderNode) {
        // var fadeIn = cc.fadeIn(0.4)
        // var fadeOut = cc.fadeOut(0.4)
        // let seq = cc.sequence(fadeIn,fadeOut)
        // let repeat = cc.repeatForever(seq)

        borderNode.active = true
        // borderNode.runAction(repeat)
    }
});
